#!/bin/sh -x

# prepare
cd /tmp
if [ -d snapshots ]; then
    echo "snapshots directory already exists. Exiting." >& 2
    exit 1
fi
mkdir snapshots

# checkout
cd snapshots
cvs -z6 -d cvs.Maxima.sourceforge.net:/cvsroot/maxima co maxima 
if [ "$?" != "0" ]; then
    echo "cvs checkout failed. Aborting"
    rmdir .
    exit 1
fi

# change CVS/Root files to anonymous
echo ':pserver:anonymous@cvs.Maxima.sourceforge.net:/cvsroot/maxima' > Root
find maxima -name Root -exec cp Root {} \;

# bootstrap
cd maxima
thisdate="`date +'%F'`"
sed "s/AM_INIT_AUTOMAKE(maxima,.*/AM_INIT_AUTOMAKE(maxima,cvs-$thisdate)/" configure.in > tmp
mv tmp configure.in
./bootstrap

# build docs
cd ..
cp -r maxima maxima-doc
cd maxima-doc
./configure
cd doc/info
make
cp *.info* *.html ../../../maxima/doc/info
cd ../../..

# make archives
maximadate="maxima-$thisdate"
mv maxima "$maximadate"
zip -r "$maximadate".zip "$maximadate"
tar zcf "$maximadate".tar.gz "$maximadate"

